$(document).ready(function() {
	showRole();
    $('#ss').searchbox({
        searcher:function(value,name){
        	showRole(value);
        },
        menu:'#mm',
        prompt:'请输入姓名'
    });
});
function showRole(name) {
	$("#roleManage")
			.datagrid(
					{
						url : "powermanage_showRoleManageList.do?name="+name,
						rownumbers : true,
						pagination : true,
						rownumber : true,
						fitColumns : true,
						striped : true,
						collapsible : true,
						remoteSort : false,
						width : 500,
						nowrap : false,
						checkOnSelect : false,
						singleSelect : true,
						loadMsg : '数据加载中，请稍等...',
						columns : [ [
								{
									field : 'userName',
									title : '用户名',
									width : 100,
									align : 'center'
								},
								{
									field : 'roleName',
									title : '角色',
									width : 100,
									align : 'center',
								},
								{
									field : 'update',
									title : '操作',
									width : 100,
									align : 'center',
									formatter : function(value, rowData,
											rowIndex) {
										return "<a href='javascript:void(0);' onclick='roleDelete("
												+ parseInt(rowData.id)
												+ ")'>删除</a>";
									}
								} ] ]
					});
}

function _save() {
	var powerId = $("#powerId").val();
	var power = $("#power").val();
	$.post("powermanage_update.do", {
		"powerId" : powerId,
		"power" : power
	}, function(data) {
		if (data.success == "success") {
			$.messager.alert("提示", "操作成功");
			showRole();
			$("#add_role").dialog({
				closed : true
			});
		} else {
			$.messager.alert("提示", "操作失败");
		}
	}, "json");
}
function roleDelete(id) {
	$.post("powermanage_delete.do", {
		"id" : id
	}, function(data) {
		if (data.success == "success") {
			$.messager.alert("提示", "操作成功");
			showRole();
		} else {
			$.messager.alert("提示", "操作失败");
		}
	}, "json");
}

function showDialog() {
	$("#add_role").dialog({
		closed : false
	});
}